package com.gallop.mq.core.template.handler.registry;

public interface RegistryHolder {

    MessageDeliveryHandlerRegistry getHandlerRegistry();

    void setHandlerRegistry(MessageDeliveryHandlerRegistry registry);

    MessageDeliveryHandlerRegistry.InitializerBuilder registryInitializer();

    default void initRegistry(MessageDeliveryHandlerRegistry registry) {
        setHandlerRegistry(registry);
        MessageDeliveryHandlerRegistry.InitializerBuilder initializer = registryInitializer();
        registry.setPreprocessor(initializer.getRegistryPreprocessor());
        initializer.getHandlerMap().forEach(registry::registerHandler);
    }
}
